// The payment page
// ================

define(['zepto', 'utils', 'wxpay', 'wxshare', 'sui'], function($, utils, wxpay, wxshare) {
  return {

    init: function(data) {
      this.orderId = parseInt(data.orderId)
      this.onConfirmBtnClick()
    },
    
    /**
     * Bind handler on clicking wx payment button
     */
    onConfirmBtnClick: function(orderId) {
      var that = this
      $('#order-confirm').on("click", function(e) {
        e.preventDefault()
        that.requestConfirm()
      }) 
    },

    requestConfirm: function() {
      $.showPreloader('正在提交')
      var that = this
      $.ajax({
        type: 'POST',
        url: __CTX__.root + '/confirm',
        dataType:"json",
        data: {
          'orderId': this.orderId
        }
      }).done(function(response) {
        if(response.code == 0) {
          $.toast('提交成功，正在为您跳转');
          setTimeout(function() {
            location.href = __CTX__.root + '/orders/' + that.orderId + "/complete"
          }, 1000)
        } else {
          $.hidePreloader();
          $.toast('提交失败');
        }
      });
    }
  }
})